﻿using System;
using System.Collections.Generic;
using ThingyCloudWPF.Creatures;

namespace ThingyCloudWPF.Network.Messages
{
	public class ActiveIdsMessage : Message
	{
		public List<int> IDs { get; private set; }

		/// <summary>
		/// The string to be sent
		/// </summary>
		string activeIds = "";

		/// <summary>
		/// Construct the message. We need a list of avatars and thingies. Constructs the string to
		/// be send immediately, disposes the lists asap.
		/// </summary>
		public ActiveIdsMessage(List<Avatar> avatars, List<Thingy> thingies)
		{
			IDs = new List<int>();

			if (avatars.Count > 0 || thingies.Count > 0)
			{
				foreach (Avatar a in avatars)
				{
					activeIds += a.ID + ",";
					IDs.Add(a.ID);
				}

				foreach (Thingy t in thingies)
				{
					activeIds += t.ID + ",";
					IDs.Add(t.ID);
				}

				activeIds = activeIds.Substring(0, activeIds.Length - 1);
			}
		}

		/// <summary>
		/// Build the message
		/// </summary>
		/// <returns></returns>
		public override string ToMessageString()
		{
			return "activeids:" + activeIds + ";";
		}
	}
}
